<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="order_id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input-number v-model="model.orderId" placeholder="请输入order_id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退货商品id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuId">
              <a-input-number v-model="model.skuId" placeholder="请输入退货商品id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderSn">
              <a-input v-model="model.orderSn" placeholder="请输入订单编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="会员用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="memberUsername">
              <a-input v-model="model.memberUsername" placeholder="请输入会员用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="returnAmount">
              <a-input-number v-model="model.returnAmount" placeholder="请输入退款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退货人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="returnName">
              <a-input v-model="model.returnName" placeholder="请输入退货人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退货人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="returnPhone">
              <a-input v-model="model.returnPhone" placeholder="请输入退货人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleTime">
              <j-date placeholder="请选择处理时间" v-model="model.handleTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuImg">
              <a-input v-model="model.skuImg" placeholder="请输入商品图片"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuName">
              <a-input v-model="model.skuName" placeholder="请输入商品名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品品牌" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuBrand">
              <a-input v-model="model.skuBrand" placeholder="请输入商品品牌"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品销售属性(JSON)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuAttrsVals">
              <a-input v-model="model.skuAttrsVals" placeholder="请输入商品销售属性(JSON)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退货数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuCount">
              <a-input-number v-model="model.skuCount" placeholder="请输入退货数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuPrice">
              <a-input-number v-model="model.skuPrice" placeholder="请输入商品单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品实际支付单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="skuRealPrice">
              <a-input-number v-model="model.skuRealPrice" placeholder="请输入商品实际支付单价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reason">
              <a-input v-model="model.reason" placeholder="请输入原因"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="description述">
              <a-input v-model="model.description述" placeholder="请输入描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="凭证图片，以逗号隔开" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="descPics">
              <a-input v-model="model.descPics" placeholder="请输入凭证图片，以逗号隔开"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleNote">
              <a-input v-model="model.handleNote" placeholder="请输入处理备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理人员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handleMan">
              <a-input v-model="model.handleMan" placeholder="请输入处理人员"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveMan">
              <a-input v-model="model.receiveMan" placeholder="请输入收货人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveTime">
              <j-date placeholder="请选择收货时间" v-model="model.receiveTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveNote">
              <a-input v-model="model.receiveNote" placeholder="请输入收货备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivePhone">
              <a-input v-model="model.receivePhone" placeholder="请输入收货电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司收货地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyAddress">
              <a-input v-model="model.companyAddress" placeholder="请输入公司收货地址"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'OmsOrderReturnApplyForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/order/omsOrderReturnApply/add",
          edit: "/order/omsOrderReturnApply/edit",
          queryById: "/order/omsOrderReturnApply/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>